/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.nii.qlks.GUI.Render;

import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Font;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeCellRenderer;

/**
 *
 * @author KUUT
 */
public class Menutree_cellrender implements TreeCellRenderer{
    private JLabel label;
    
        public Menutree_cellrender() {
            label = new JLabel();
        }

        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            Object o = ((DefaultMutableTreeNode) value).getUserObject();
            
            if (o instanceof Menutree) {
                Menutree menutree = (Menutree) o;
                label.setIcon(new ImageIcon(getClass().getResource("/icon/icon/" + menutree.getFlagIcon())));
                label.setText(menutree.getName());
                
            } else {
                label.setIcon(null);
                label.setText("" + value);
                label.setFont(new Font(null, Font.PLAIN, 14));
                label.setForeground(Color.black);
            }
            
            int level = ((DefaultMutableTreeNode) value).getLevel();
            
            if(level == 0 ) {
                label.setIcon(new ImageIcon(getClass().getResource("/icon/icon/hotel.png")));
                
            }else if(level == 1) {
                label.setIcon(new ImageIcon(getClass().getResource("/icon/icon/user.png")));
                label.setFont(new Font(null, Font.PLAIN, 12));
                label.setForeground(Color.black);
            }
            else{
                label.setForeground(Color.RED);
            }
            
            
            return label;
        }
}
